const fetch = require('node-fetch')
const fs = require('fs')
const FormData = require('form-data')

const API_KEY = '008530ac7c65df4073117211a3aba7ae'
const USER_KEY = '7bd7b04bd624cbfc0c182c22dd406ab3'

exports.update = async (filename, updateDescription) => {
  let result
  let form = new FormData({ maxDataSize: 1024 * 1024 * 100 })
  form.append('uKey', USER_KEY)
  form.append('_api_key', API_KEY)
  form.append('updateDescription', updateDescription)
  form.append('file', fs.createReadStream(filename))
  await fetch('https://qiniu-storage.pgyer.com/apiv1/app/upload', {
    method: 'POST',
    body: form
  })
    .then(res => {
      result = res.json()
    })
    .catch(err => {
      result = err
    })
  return result
}